using System;
using System.Data;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Anthem;
using BusinessRules;
using Common;
using DataAccess;
using UsrControls;

public partial class SitiosEjecucion : PageBase
{
    #region IdentificadorAccId

    public string IdentificadorAccId
    {
        get { return (ViewState["IdentificadorAccId"] == null ? string.Empty : ViewState["IdentificadorAccId"].ToString()); }
        set { ViewState["IdentificadorAccId"] = value; }
    }

    #endregion

    #region IdentificadorPazId

    public string IdentificadorPazId
    {
        get { return (ViewState["IdentificadorPazId"] == null ? string.Empty : ViewState["IdentificadorPazId"].ToString()); }
        set { ViewState["IdentificadorPazId"] = value; }
    }

    #endregion

    #region IdentificadorMetId

    public string IdentificadorMetId
    {
        get { return (ViewState["IdentificadorMetId"] == null ? string.Empty : ViewState["IdentificadorMetId"].ToString()); }
        set { ViewState["IdentificadorMetId"] = value; }
    }

    #endregion

    #region IdentificadorSasId

    public string IdentificadorSasId
    {
        get { return (ViewState["IdentificadorSasId"] == null ? string.Empty : ViewState["IdentificadorSasId"].ToString()); }
        set { ViewState["IdentificadorSasId"] = value; }
    }

    #endregion

    #region IdentificadorSacId

    public string IdentificadorSacId
    {
        get { return (ViewState["IdentificadorSacId"] == null ? string.Empty : ViewState["IdentificadorSacId"].ToString()); }
        set { ViewState["IdentificadorSacId"] = value; }
    }

    #endregion

    #region StrPlnId

    public string StrPlnId
    {
        get
        {
            if (ViewState["strPlnId"] != null)
                return ViewState["strPlnId"].ToString();
            else
                return "";
        }
        set { ViewState["strPlnId"] = value; }
    }

    #endregion


    #region Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        WccAcciones1.AddEnabledDuringCallBack = false;
        WccAcciones1.AddTextDuringCallBack = "Guardando... Por favor esperar!!!";
        WccAcciones1.UpdateEnabledDuringCallBack = false;
        WccAcciones1.UpdateTextDuringCallBack = "Guardando... Por favor espere!!!";

        if (Manager.IsCallBack)
        {
            Manager.RegisterClientScriptBlock(typeof(Page), "reloj", "<script>muestraReloj2();</script>");
        }
        WccAcciones1.Permisos = Permisos;
        if (!Page.IsPostBack)
        {
            cargarDepartamentos();
            TraerContextItems();
            cargarCamposEncabezado();
            if (IdentificadorPazId != "")
            {
                cargarCampos();
                WccAcciones1.Accion = Utilidad.Acciones.Actualizar;
                WccAcciones1.AddVisible = false;
                WccAcciones1.UpdateVisible = true;
                WccAcciones1.DeleteVisible = true;

            }
            else
            {
                WccAcciones1.Accion = Utilidad.Acciones.Adicionar;
            }
        }
    }

    #endregion

    #region cargarCamposEncabezado

    private void cargarCamposEncabezado()
    {
        try
        {
            SigPlanAccion objSigPlanAccion = new SigPlanAccion(ConfigurationManager.AppSettings["Conn"]);
            SigPlanAccionData objSigPlanAccionData = objSigPlanAccion.ConsultarPnlId(Convert.ToDecimal(StrPlnId));
            if (objSigPlanAccionData != null)
            {
                DataRow fila = objSigPlanAccionData.Rows[0];
                lblDependencia.Text = fila[SigPlanAccionData.DEP_NOMBRE_FIELD].ToString();
                lblDescripcionRubro.Text = fila[SigPlanAccionData.PLN_NOMBRE_FIELD].ToString();
                decimal decVAlor = Convert.ToDecimal(fila[SigPlanAccionData.PLN_VALOR_APROPIACION_FIELD].ToString());
                lblValorApropiacion.Text = decVAlor.ToString("C");
            }

            SigAccion objSigAccion = new SigAccion(ConfigurationManager.AppSettings["Conn"]);
            SigAccionData objSigAccionData = objSigAccion.ConsultarAccionAccID(IdentificadorAccId);
            //---------------------
            //Cargar datos Accion -
            //---------------------
            if (objSigAccionData != null)
            {
                DataRow filaAccion = objSigAccionData.Rows[0];
                lblAccion.Text = filaAccion[SigAccionData.ACC_DESCRIPCION_FIELD].ToString();

                decimal decValor = Convert.ToDecimal(filaAccion[SigAccionData.ACC_VALOR_FIELD].ToString());
                lblValorAccion.Text = decValor.ToString("C");

            }
        }
        catch (Exception ex)
        {

            lblMensaje.Visible = true;
            Utilidad.mostrarMensaje(Utilidad.TiposMensajes.Error, ex.Message, lblMensaje);
        }

    }

    #endregion

    #region TraerContextItems

    private void TraerContextItems()
    {
        if (Context.Items["plnId"] != null)
            StrPlnId = Context.Items["plnId"].ToString();
        if (Context.Items["IdentificadorSasId"] != null)
            IdentificadorSasId = Context.Items["IdentificadorSasId"].ToString();
        if (Context.Items["IdentificadorSacId"] != null)
            IdentificadorSacId = Context.Items["IdentificadorSacId"].ToString();
        if (Context.Items["IdentificadorAccId"] != null)
            IdentificadorAccId = Context.Items["IdentificadorAccId"].ToString();
        if (Context.Items["IdentificadorMetId"] != null)
            IdentificadorMetId = Context.Items["IdentificadorMetId"].ToString();
        if (Context.Items["IdentificadorPazId"] != null)
            IdentificadorPazId = Context.Items["IdentificadorPazId"].ToString();
        
        

    }

    #endregion

    #region cargarCampos

    private void cargarCampos()
    {
        SigPrgAccionZonaGeografica objBR = new SigPrgAccionZonaGeografica(ConfigurationManager.AppSettings["Conn"]);
        SigPrgAccionZonaGeograficaData objSigPrgAccionZonaGeograficaData = objBR.ConsultarSigPrgAccionZonaGeograficaPazID(Convert.ToDecimal(IdentificadorPazId));
        SigProAccionDemografica objPobla = new SigProAccionDemografica(ConfigurationManager.AppSettings["Conn"]);
        try
        {

            if (objSigPrgAccionZonaGeograficaData != null)
            {
                DataRow objRow = objSigPrgAccionZonaGeograficaData.Rows[0];
                //primero tiene qeue cargar los municipios con el departamento
                string zonidDep = objRow[SigPrgAccionZonaGeograficaData.ZON_ID_FIELD].ToString().Substring(0, 2);
                if (zonidDep != "")
                {
                    cargarMunicipios(zonidDep);
                    ddlMunicipiosAnthem.SelectedValue = objRow[SigProgramaZonasGeograficasData.ZON_ID_FIELD].ToString();
                    ddldepartamentosAnthem.SelectedValue = zonidDep;
                    cargarResguardos(ddlMunicipiosAnthem.SelectedValue);
                    if (objRow[SigPrgAccionZonaGeograficaData.RES_ID_FIELD] != DBNull.Value && objRow[SigPrgAccionZonaGeograficaData.RES_ID_FIELD].ToString() != "")
                    {
                        ddlResguardos.SelectedValue = objRow[SigPrgAccionZonaGeograficaData.RES_ID_FIELD].ToString();
                    }
                }
                txtEspecifica.Text = objRow[SigPrgAccionZonaGeograficaData.PAZ_ESPECIFICA_FIELD].ToString();
                txtOtros.Text = objRow[SigPrgAccionZonaGeograficaData.PAZ_OTROS_FIELD].ToString();

                //CARGAR POBLACIONES
                SigProAccionDemograficaData objSigProAccionDemograficaData = objPobla.consultarPazId(IdentificadorPazId);
                TextBoxBase t;
                string strtexboxBase;
                if (objSigProAccionDemograficaData != null && objSigProAccionDemograficaData.Rows.Count > 0)
                {

                    for (int i = 0; i < objSigProAccionDemograficaData.Rows.Count; i++)
                    {


                        if (Page.Master != null)
                        {
                            foreach (Control control in Page.Master.Controls)
                            {
                                if (control is HtmlForm)
                                {
                                    foreach (Control controlform in control.Controls)
                                    {
                                        if (controlform is ContentPlaceHolder)
                                        {
                                            strtexboxBase = "TextBoxBase" + (i+1);
                                            t = (TextBoxBase) controlform.FindControl(strtexboxBase);
                                            if (t != null)
                                            {
                                                t.Text =
                                                    objSigProAccionDemograficaData.Rows[i][
                                                        SigProAccionDemograficaData.PDM_CANTIDAD_FIELD].ToString();
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            t = (TextBoxBase) Page.FindControl(TextBoxBase1.ClientID);
                        }

                    }
                }
                sumatoriaTotales();

            }
        }
        catch (Exception ex)
        {

            lblMensaje.CssClass = "error";
            lblMensaje.Visible = true;
            lblMensaje.Text = Utilidad.TraerMensaje("gmsgErrorGeneral");
        }
    }

    #endregion

    #region btnRegresar_Click

    protected void btnRegresar_Click(object sender, ImageClickEventArgs e)
    {
        crearContextItems();
        Server.Transfer("SitiosEjecucionListado.aspx?SSM_ID=19", true);
    }

    #endregion

    #region crearContextItems

    private void crearContextItems()
    {
        try
        {
            Context.Items["plnId"] = StrPlnId;
            Context.Items["IdentificadorSasId"] = IdentificadorSasId;
            Context.Items["IdentificadorSacId"] = IdentificadorSacId;
            Context.Items["IdentificadorAccId"] = IdentificadorAccId;
            Context.Items["IdentificadorMetId"] = IdentificadorMetId;
            


        }
        catch (Exception ex)
        {
            lblMensaje.Text = ex.ToString();
        }
    }

    #endregion

    #region WccAcciones1_Add_OnClick

    protected void WccAcciones1_Add_OnClick(object sender, ImageClickEventArgs e)
    {
        Adcionar();
    }

    #endregion

    #region Adcionar

    private void Adcionar()
    {
        SigPrgAccionZonaGeograficaData objDS = new SigPrgAccionZonaGeograficaData();
        SigProAccionDemograficaData objDSMatriz = new SigProAccionDemograficaData();
        try
        {
            DataRow objRow = objDS.NewRow();

            //objRow[SigAccionMetaData.MET_ID_FIELD] = IdentificadorPazId;
            objRow[SigPrgAccionZonaGeograficaData.ZON_ID_FIELD] = ddlMunicipiosAnthem.SelectedValue;
            objRow[SigPrgAccionZonaGeograficaData.PAZ_ESPECIFICA_FIELD] = txtEspecifica.Text;
            objRow[SigPrgAccionZonaGeograficaData.PAZ_OTROS_FIELD] = txtOtros.Text;
            objRow[SigPrgAccionZonaGeograficaData.MET_ID_FIELD] = IdentificadorMetId;
            //ojo falta resguardo
            if (ddlResguardos.SelectedValue != "")
                objRow[SigPrgAccionZonaGeograficaData.RES_ID_FIELD] = ddlResguardos.SelectedValue;
            objDS.Add(objRow);
            SigPrgAccionZonaGeografica objBR = new SigPrgAccionZonaGeografica(ConfigurationManager.AppSettings["Conn"]);

           
            DataRow objRowMatriz = objDSMatriz.NewRow();
            TextBoxBase t;
            string strIdentificadorTextBox = "TextBoxBase";
            for (int i = 1; i < 26; i++)
            {
                if (Page.Master != null)
                {
                    foreach (Control control in Page.Master.Controls)
                    {
                        if (control is HtmlForm)
                        {
                            foreach (Control controlform in control.Controls)
                            {
                                if (controlform is ContentPlaceHolder)
                                {
                                    strIdentificadorTextBox = "TextBoxBase" + i.ToString();
                                    t = (TextBoxBase)controlform.FindControl(strIdentificadorTextBox);
                                    if (t != null)
                                    {
                                        objRowMatriz = objDSMatriz.NewRow();
                                        objRowMatriz[SigProAccionDemograficaData.VAL_ID_FIELD] = i;
                                        objRowMatriz[SigProAccionDemograficaData.PDM_CANTIDAD_FIELD] = t.Text;
                                        objDSMatriz.Add(objRowMatriz);
                                        break;
                                    }

                                }
                            }
                        }
                    }
                }
                else
                {
                    t = (TextBoxBase)Page.FindControl(TextBoxBase1.ClientID);
                }
            }
            

            IdentificadorPazId = objBR.AdicionarSitiosContransacciones(objDS, objDSMatriz).ToString();

            lblMensaje.Visible = true;

            Utilidad.mostrarMensaje(Utilidad.TiposMensajes.Mensaje, Utilidad.TraerMensaje("gmsgExitoGuardar"), lblMensaje);
            WccAcciones1.Accion = Utilidad.Acciones.Actualizar;
            WccAcciones1.AddVisible = false;
            WccAcciones1.UpdateVisible = true;
            WccAcciones1.DeleteVisible = true;
        }
        catch (Exception objEx)
        {
            //ExceptionManager.Publish(objEx);
            lblMensaje.Visible = true;
            Utilidad.mostrarMensaje(Utilidad.TiposMensajes.Error, Utilidad.TraerMensaje("gmsgErrorGeneral"), lblMensaje);
        }


    }

    #endregion

    #region Actualizar

    private void Actualizar()
    {
        SigPrgAccionZonaGeograficaData objDS = new SigPrgAccionZonaGeograficaData();
        SigProAccionDemograficaData objDSMatriz = new SigProAccionDemograficaData();
        try
        {
            DataRow objRow = objDS.NewRow();

            objRow[SigPrgAccionZonaGeograficaData.PAZ_ID_FIELD] = IdentificadorPazId;
            objRow[SigPrgAccionZonaGeograficaData.ZON_ID_FIELD] = ddlMunicipiosAnthem.SelectedValue;
            objRow[SigPrgAccionZonaGeograficaData.PAZ_ESPECIFICA_FIELD] = txtEspecifica.Text;
            objRow[SigPrgAccionZonaGeograficaData.PAZ_OTROS_FIELD] = txtOtros.Text;
            objRow[SigPrgAccionZonaGeograficaData.MET_ID_FIELD] = IdentificadorMetId;
            //ojo falta resguardo
            if (ddlResguardos.SelectedValue != "")
                objRow[SigPrgAccionZonaGeograficaData.RES_ID_FIELD] = ddlResguardos.SelectedValue;
            objDS.Add(objRow);
            SigPrgAccionZonaGeografica objBR = new SigPrgAccionZonaGeografica(ConfigurationManager.AppSettings["Conn"]);


            DataRow objRowMatriz = objDSMatriz.NewRow();
            //CARGAR POBLACIONES
            
            TextBoxBase t;
            string strIdentificadorTextBox = "TextBoxBase";

            for (int i = 1; i < 27; i++)
            {
                if (Page.Master != null)
                {
                    foreach (Control control in Page.Master.Controls)
                    {
                        if (control is HtmlForm)
                        {
                            foreach (Control controlform in control.Controls)
                            {
                                if (controlform is ContentPlaceHolder)
                                {
                                    strIdentificadorTextBox = "TextBoxBase" + i.ToString();
                                    t = (TextBoxBase) controlform.FindControl(strIdentificadorTextBox);
                                    if (t != null)
                                    {
                                        objRowMatriz = objDSMatriz.NewRow();
                                        objRowMatriz[SigProAccionDemograficaData.VAL_ID_FIELD] = i;
                                        objRowMatriz[SigProAccionDemograficaData.PAZ_ID_FIELD] = Convert.ToDecimal(IdentificadorPazId);
                                        objRowMatriz[SigProAccionDemograficaData.PDM_CANTIDAD_FIELD] = t.Text;
                                        objDSMatriz.Add(objRowMatriz);
                                        break;
                                    }

                                }
                            }
                        }
                    }
                }
                else
                {
                    t = (TextBoxBase) Page.FindControl(TextBoxBase1.ClientID);
                }
            }

            objBR.ActualizarSitiosContransacciones(objDS, objDSMatriz);

            lblMensaje.Visible = true;
            Utilidad.mostrarMensaje(Utilidad.TiposMensajes.Mensaje, Utilidad.TraerMensaje("gmsgExitoGuardar"), lblMensaje);
            WccAcciones1.Accion = Utilidad.Acciones.Actualizar;
            WccAcciones1.AddVisible = false;
            WccAcciones1.UpdateVisible = true;
            WccAcciones1.DeleteVisible = true;
            //lnkMetas.Enabled = true;
            //lnkMetas.AutoUpdateAfterCallBack = true;
        }
        catch (Exception objEx)
        {
            //ExceptionManager.Publish(objEx);
            lblMensaje.Visible = true;
            Utilidad.mostrarMensaje(Utilidad.TiposMensajes.Error, Utilidad.TraerMensaje("gmsgErrorGeneral"), lblMensaje);
        }
    }

    #endregion


    #region WccAcciones1_Delete_OnClick

    protected void WccAcciones1_Delete_OnClick(object sender, ImageClickEventArgs e)
    {
        
            
        try
        {
            string[] strIDs = new string[1];
            strIDs[0] = IdentificadorPazId;
            SigPrgAccionZonaGeografica objBR = new SigPrgAccionZonaGeografica(ConfigurationManager.AppSettings["Conn"]);
            if (objBR.eliminarConTransacciones(strIDs) != 0)
            {
                LimpiarCamposPagina();
                WccAcciones1.Accion = Utilidad.Acciones.Adicionar;
                WccAcciones1.AddVisible = true;
                WccAcciones1.UpdateVisible = false;
                WccAcciones1.DeleteVisible = false;
                lblMensaje.Visible = true;
                Utilidad.mostrarMensaje(Utilidad.TiposMensajes.Mensaje, Utilidad.TraerMensaje("gmsgEliminarRegistrosExitoso"), lblMensaje);
            }
        }

        catch (Exception ex)
        {
            lblMensaje.CssClass = "error";
            lblMensaje.Visible = true;
            lblMensaje.Text = Utilidad.TraerMensaje("gmsgErrorGeneral");
        }

           

    }

    #endregion

    #region LimpiarCamposPagina

    private  void LimpiarCamposPagina()
    {
        txtEspecifica.Text = "";
        txtOtros.Text = "";
        ddldepartamentosAnthem.SelectedIndex = 0;
        ddlMunicipiosAnthem.SelectedIndex = 0;
        txtEspecifica.AutoUpdateAfterCallBack = true;
        txtOtros.AutoUpdateAfterCallBack = true;
        ddlMunicipiosAnthem.AutoUpdateAfterCallBack = true;

        TextBoxBase t;
        string strIdentificadorTextBox = "TextBoxBase";

        for (int i = 1; i < 27; i++)
        {
            if (Page.Master != null)
            {
                foreach (Control control in Page.Master.Controls)
                {
                    if (control is HtmlForm)
                    {
                        foreach (Control controlform in control.Controls)
                        {
                            if (controlform is ContentPlaceHolder)
                            {
                                strIdentificadorTextBox = "TextBoxBase" + i.ToString();
                                t = (TextBoxBase)controlform.FindControl(strIdentificadorTextBox);
                                if (t != null)
                                {
                                    t.Text = "0";
                                    t.AutoUpdateAfterCallBack = true;

                                    break;
                                }

                            }
                        }
                    }
                }
            }
            else
            {
                t = (TextBoxBase)Page.FindControl(TextBoxBase1.ClientID);
            }
        }
    }

    #endregion


    #region WccAcciones1_Update_OnClick

    protected void WccAcciones1_Update_OnClick(object sender, ImageClickEventArgs e)
    {
        Actualizar();
    }

    #endregion

    #region limpiarGrupos

    private void limpiarGrupos()
    {
        BasDependenciaData objBasDependenciaData = new BasDependenciaData();
        //ddlGrupos.DataSource = objBasDependenciaData;
        //ddlGrupos.DataValueField = BasDependenciaData.DEP_ID_FIELD;
        //ddlGrupos.DataTextField = BasDependenciaData.DEP_NOMBRE_FIELD;
        //ddlGrupos.DataBind();
        //ddlGrupos.Items.Insert(0, new ListItem("Todos", "0"));
        //ddlGrupos.SelectedIndex = 0;
    }

    #endregion

    #region lnkModificaciones_Click

    protected void lnkModificaciones_Click(object sender, EventArgs e)
    {
        crearContextItems();
        Server.Transfer("MetasListado.aspx?SSM_ID=19", true);
    }

    #endregion

    #region lnkPlanAAccion_Click

    protected void lnkPlanAAccion_Click(object sender, EventArgs e)
    {
        crearContextItems();
        Server.Transfer("SitiosEjecucionListado.aspx?SSM_ID=19", true);
    }

    #endregion

    #region ddldepartamentosAnthem_SelectedIndexChanged

    protected void ddldepartamentosAnthem_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddldepartamentosAnthem.SelectedValue != "")
        {
            cargarMunicipios(ddldepartamentosAnthem.SelectedValue);
        }
    }

    #endregion

    #region Cargar Departamentos

    private void cargarDepartamentos()
    {
        BasZonasGeograficas objBasZonasGeograficas = new BasZonasGeograficas(ConfigurationManager.AppSettings["Conn"]);
        BasZonasGeograficasData objBasZonasGeograficasData = objBasZonasGeograficas.ConsultarZonasGeograficasDepartamento();
        ddldepartamentosAnthem.DataSource = objBasZonasGeograficasData;
        ddldepartamentosAnthem.DataValueField = BasZonasGeograficasData.ZON_ID_FIELD;
        ddldepartamentosAnthem.DataTextField = BasZonasGeograficasData.ZON_NOMBRE_FIELD;
        ddldepartamentosAnthem.DataBind();
        ddldepartamentosAnthem.Items.Insert(0, new ListItem("", ""));
        ddldepartamentosAnthem.SelectedIndex = 0;

    }

    #endregion

    #region Cargar Municipios

    public void cargarMunicipios(string strZonIdPadre)
    {
        BasZonasGeograficas objBasZonasGeograficas = new BasZonasGeograficas(ConfigurationManager.AppSettings["Conn"]);
        BasZonasGeograficasData objBasZonasGeograficasData = objBasZonasGeograficas.ConsultarZonasGeograficasPadreZonId(strZonIdPadre);
        ddlMunicipiosAnthem.DataSource = objBasZonasGeograficasData;
        ddlMunicipiosAnthem.DataValueField = BasZonasGeograficasData.ZON_ID_FIELD;
        ddlMunicipiosAnthem.DataTextField = BasZonasGeograficasData.ZON_NOMBRE_FIELD;
        ddlMunicipiosAnthem.DataBind();


        ddlMunicipiosAnthem.UpdateAfterCallBack = true;
        //LimpiarPlanPrograma();
    }

    #endregion

    #region cargarResguardos

    public void cargarResguardos(string strZonId)
    {
        BasResguardos objBasResguardos = new BasResguardos(ConfigurationManager.AppSettings["Conn"]);
        BasResguardosData objBasResguardosData = objBasResguardos.ConsultarResguardos(strZonId);
        ddlResguardos.DataSource = objBasResguardosData;
        ddlResguardos.DataValueField = BasResguardosData.RES_ID_FIELD;
        ddlResguardos.DataTextField = BasResguardosData.RES_NOMBRE_FIELD;
        ddlResguardos.DataBind();
        ddlResguardos.Items.Insert(0, new ListItem("", ""));
        ddlResguardos.SelectedIndex = 0;

        ddlResguardos.UpdateAfterCallBack = true;
        //LimpiarPlanPrograma();
    }

    #endregion

    #region ddlMunicipiosAnthem_SelectedIndexChanged

    protected void ddlMunicipiosAnthem_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlMunicipiosAnthem.SelectedValue != "")
        {
            cargarResguardos(ddlMunicipiosAnthem.SelectedValue);
        }
    }

    #endregion

    protected void TextBoxBase5_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase5.Text != string.Empty)
        {
            int intTextBoxBase5 = Convert.ToInt32(TextBoxBase5.Text);
            int intTextBoxBase6 = Convert.ToInt32(TextBoxBase6.Text);
            int intTextBoxBase7 = Convert.ToInt32(TextBoxBase7.Text);
            int intTextBoxBase8 = Convert.ToInt32(TextBoxBase8.Text);

            int total = intTextBoxBase5 + intTextBoxBase6 + intTextBoxBase7 + intTextBoxBase8;

            txtTotal5A8.Text = total.ToString();
            txtTotal5A8.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase6_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase6.Text != string.Empty)
        {
            int intTextBoxBase5 = Convert.ToInt32(TextBoxBase5.Text);
            int intTextBoxBase6 = Convert.ToInt32(TextBoxBase6.Text);
            int intTextBoxBase7 = Convert.ToInt32(TextBoxBase7.Text);
            int intTextBoxBase8 = Convert.ToInt32(TextBoxBase8.Text);

            int total = intTextBoxBase5 + intTextBoxBase6 + intTextBoxBase7 + intTextBoxBase8;

            txtTotal5A8.Text = total.ToString();
            txtTotal5A8.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase7_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase7.Text != string.Empty)
        {
            int intTextBoxBase5 = Convert.ToInt32(TextBoxBase5.Text);
            int intTextBoxBase6 = Convert.ToInt32(TextBoxBase6.Text);
            int intTextBoxBase7 = Convert.ToInt32(TextBoxBase7.Text);
            int intTextBoxBase8 = Convert.ToInt32(TextBoxBase8.Text);

            int total = intTextBoxBase5 + intTextBoxBase6 + intTextBoxBase7 + intTextBoxBase8;

            txtTotal5A8.Text = total.ToString();
            txtTotal5A8.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase8_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase8.Text != string.Empty)
        {
            int intTextBoxBase5 = Convert.ToInt32(TextBoxBase5.Text);
            int intTextBoxBase6 = Convert.ToInt32(TextBoxBase6.Text);
            int intTextBoxBase7 = Convert.ToInt32(TextBoxBase7.Text);
            int intTextBoxBase8 = Convert.ToInt32(TextBoxBase8.Text);

            int total = intTextBoxBase5 + intTextBoxBase6 + intTextBoxBase7 + intTextBoxBase8;

            txtTotal5A8.Text = total.ToString();
            txtTotal5A8.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase9_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase9.Text != string.Empty)
        {
            int intTextBoxBase9 = Convert.ToInt32(TextBoxBase9.Text);
            int intTextBoxBase10 = Convert.ToInt32(TextBoxBase10.Text);
            

            int total = intTextBoxBase9 + intTextBoxBase10 ;

            txtTotal9y10.Text = total.ToString();
            txtTotal9y10.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase10_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase10.Text != string.Empty)
        {
            int intTextBoxBase9 = Convert.ToInt32(TextBoxBase9.Text);
            int intTextBoxBase10 = Convert.ToInt32(TextBoxBase10.Text);


            int total = intTextBoxBase9 + intTextBoxBase10;

            txtTotal9y10.Text = total.ToString();
            txtTotal9y10.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase11_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase11.Text != string.Empty)
        {
            int intTextBoxBase11 = Convert.ToInt32(TextBoxBase11.Text);
            int intTextBoxBase12 = Convert.ToInt32(TextBoxBase12.Text);
            int intTextBoxBase13 = Convert.ToInt32(TextBoxBase13.Text);
            int intTextBoxBase14 = Convert.ToInt32(TextBoxBase14.Text);
            int intTextBoxBase15 = Convert.ToInt32(TextBoxBase15.Text);
            int intTextBoxBase16 = Convert.ToInt32(TextBoxBase16.Text);

            int total = intTextBoxBase11 + intTextBoxBase12 + intTextBoxBase13 + intTextBoxBase14 + +intTextBoxBase15 + intTextBoxBase16;

            txtTotal11A16.Text = total.ToString();
            txtTotal11A16.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase12_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase12.Text != string.Empty)
        {
            int intTextBoxBase11 = Convert.ToInt32(TextBoxBase11.Text);
            int intTextBoxBase12 = Convert.ToInt32(TextBoxBase12.Text);
            int intTextBoxBase13 = Convert.ToInt32(TextBoxBase13.Text);
            int intTextBoxBase14 = Convert.ToInt32(TextBoxBase14.Text);
            int intTextBoxBase15 = Convert.ToInt32(TextBoxBase15.Text);
            int intTextBoxBase16 = Convert.ToInt32(TextBoxBase16.Text);

            int total = intTextBoxBase11 + intTextBoxBase12 + intTextBoxBase13 + intTextBoxBase14 + +intTextBoxBase15 + intTextBoxBase16;

            txtTotal11A16.Text = total.ToString();
            txtTotal11A16.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase13_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase13.Text != string.Empty)
        {
            int intTextBoxBase11 = Convert.ToInt32(TextBoxBase11.Text);
            int intTextBoxBase12 = Convert.ToInt32(TextBoxBase12.Text);
            int intTextBoxBase13 = Convert.ToInt32(TextBoxBase13.Text);
            int intTextBoxBase14 = Convert.ToInt32(TextBoxBase14.Text);
            int intTextBoxBase15 = Convert.ToInt32(TextBoxBase15.Text);
            int intTextBoxBase16 = Convert.ToInt32(TextBoxBase16.Text);

            int total = intTextBoxBase11 + intTextBoxBase12 + intTextBoxBase13 + intTextBoxBase14 + +intTextBoxBase15 + intTextBoxBase16;

            txtTotal11A16.Text = total.ToString();
            txtTotal11A16.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase14_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase14.Text != string.Empty)
        {
            int intTextBoxBase11 = Convert.ToInt32(TextBoxBase11.Text);
            int intTextBoxBase12 = Convert.ToInt32(TextBoxBase12.Text);
            int intTextBoxBase13 = Convert.ToInt32(TextBoxBase13.Text);
            int intTextBoxBase14 = Convert.ToInt32(TextBoxBase14.Text);
            int intTextBoxBase15 = Convert.ToInt32(TextBoxBase15.Text);
            int intTextBoxBase16 = Convert.ToInt32(TextBoxBase16.Text);

            int total = intTextBoxBase11 + intTextBoxBase12 + intTextBoxBase13 + intTextBoxBase14 + +intTextBoxBase15 + intTextBoxBase16;

            txtTotal11A16.Text = total.ToString();
            txtTotal11A16.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase15_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase15.Text != string.Empty)
        {
            int intTextBoxBase11 = Convert.ToInt32(TextBoxBase11.Text);
            int intTextBoxBase12 = Convert.ToInt32(TextBoxBase12.Text);
            int intTextBoxBase13 = Convert.ToInt32(TextBoxBase13.Text);
            int intTextBoxBase14 = Convert.ToInt32(TextBoxBase14.Text);
            int intTextBoxBase15 = Convert.ToInt32(TextBoxBase15.Text);
            int intTextBoxBase16 = Convert.ToInt32(TextBoxBase16.Text);

            int total = intTextBoxBase11 + intTextBoxBase12 + intTextBoxBase13 + intTextBoxBase14 + +intTextBoxBase15 + intTextBoxBase16;

            txtTotal11A16.Text = total.ToString();
            txtTotal11A16.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase16_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase16.Text != string.Empty)
        {
            int intTextBoxBase11 = Convert.ToInt32(TextBoxBase11.Text);
            int intTextBoxBase12 = Convert.ToInt32(TextBoxBase12.Text);
            int intTextBoxBase13 = Convert.ToInt32(TextBoxBase13.Text);
            int intTextBoxBase14 = Convert.ToInt32(TextBoxBase14.Text);
            int intTextBoxBase15 = Convert.ToInt32(TextBoxBase15.Text);
            int intTextBoxBase16 = Convert.ToInt32(TextBoxBase16.Text);

            int total = intTextBoxBase11 + intTextBoxBase12 + intTextBoxBase13 + intTextBoxBase14 + +intTextBoxBase15 + intTextBoxBase16;

            txtTotal11A16.Text = total.ToString();
            txtTotal11A16.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase17_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase17.Text != string.Empty)
        {
            int intTextBoxBase17 = Convert.ToInt32(TextBoxBase17.Text);
            int intTextBoxBase18 = Convert.ToInt32(TextBoxBase18.Text);
            int intTextBoxBase19 = Convert.ToInt32(TextBoxBase19.Text);
            int intTextBoxBase20 = Convert.ToInt32(TextBoxBase20.Text);
            int intTextBoxBase21 = Convert.ToInt32(TextBoxBase21.Text);
            

            int total = intTextBoxBase17 + intTextBoxBase18 + intTextBoxBase19 + intTextBoxBase20 + +intTextBoxBase21;

            txtTotal17A21.Text = total.ToString();
            txtTotal17A21.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase18_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase18.Text != string.Empty)
        {
            int intTextBoxBase17 = Convert.ToInt32(TextBoxBase17.Text);
            int intTextBoxBase18 = Convert.ToInt32(TextBoxBase18.Text);
            int intTextBoxBase19 = Convert.ToInt32(TextBoxBase19.Text);
            int intTextBoxBase20 = Convert.ToInt32(TextBoxBase20.Text);
            int intTextBoxBase21 = Convert.ToInt32(TextBoxBase21.Text);


            int total = intTextBoxBase17 + intTextBoxBase18 + intTextBoxBase19 + intTextBoxBase20 + +intTextBoxBase21;

            txtTotal17A21.Text = total.ToString();
            txtTotal17A21.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase19_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase19.Text != string.Empty)
        {
            int intTextBoxBase17 = Convert.ToInt32(TextBoxBase17.Text);
            int intTextBoxBase18 = Convert.ToInt32(TextBoxBase18.Text);
            int intTextBoxBase19 = Convert.ToInt32(TextBoxBase19.Text);
            int intTextBoxBase20 = Convert.ToInt32(TextBoxBase20.Text);
            int intTextBoxBase21 = Convert.ToInt32(TextBoxBase21.Text);


            int total = intTextBoxBase17 + intTextBoxBase18 + intTextBoxBase19 + intTextBoxBase20 + +intTextBoxBase21;

            txtTotal17A21.Text = total.ToString();
            txtTotal17A21.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase20_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase20.Text != string.Empty)
        {
            int intTextBoxBase17 = Convert.ToInt32(TextBoxBase17.Text);
            int intTextBoxBase18 = Convert.ToInt32(TextBoxBase18.Text);
            int intTextBoxBase19 = Convert.ToInt32(TextBoxBase19.Text);
            int intTextBoxBase20 = Convert.ToInt32(TextBoxBase20.Text);
            int intTextBoxBase21 = Convert.ToInt32(TextBoxBase21.Text);


            int total = intTextBoxBase17 + intTextBoxBase18 + intTextBoxBase19 + intTextBoxBase20 + +intTextBoxBase21;

            txtTotal17A21.Text = total.ToString();
            txtTotal17A21.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase21_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase21.Text != string.Empty)
        {
            int intTextBoxBase17 = Convert.ToInt32(TextBoxBase17.Text);
            int intTextBoxBase18 = Convert.ToInt32(TextBoxBase18.Text);
            int intTextBoxBase19 = Convert.ToInt32(TextBoxBase19.Text);
            int intTextBoxBase20 = Convert.ToInt32(TextBoxBase20.Text);
            int intTextBoxBase21 = Convert.ToInt32(TextBoxBase21.Text);


            int total = intTextBoxBase17 + intTextBoxBase18 + intTextBoxBase19 + intTextBoxBase20 + +intTextBoxBase21;

            txtTotal17A21.Text = total.ToString();
            txtTotal17A21.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase22_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase22.Text != string.Empty)
        {
            int intTextBoxBase22 = Convert.ToInt32(TextBoxBase22.Text);
            int intTextBoxBase23 = Convert.ToInt32(TextBoxBase23.Text);
            int intTextBoxBase24 = Convert.ToInt32(TextBoxBase24.Text);
            int intTextBoxBase25 = Convert.ToInt32(TextBoxBase25.Text);
            int intTextBoxBase26 = Convert.ToInt32(TextBoxBase26.Text);


            int total = intTextBoxBase22 + intTextBoxBase23 + intTextBoxBase24 + intTextBoxBase25 + +intTextBoxBase26;

            txtTotal22A26.Text = total.ToString();
            txtTotal22A26.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase23_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase23.Text != string.Empty)
        {
            int intTextBoxBase22 = Convert.ToInt32(TextBoxBase22.Text);
            int intTextBoxBase23 = Convert.ToInt32(TextBoxBase23.Text);
            int intTextBoxBase24 = Convert.ToInt32(TextBoxBase24.Text);
            int intTextBoxBase25 = Convert.ToInt32(TextBoxBase25.Text);
            int intTextBoxBase26 = Convert.ToInt32(TextBoxBase26.Text);


            int total = intTextBoxBase22 + intTextBoxBase23 + intTextBoxBase24 + intTextBoxBase25 + +intTextBoxBase26;

            txtTotal22A26.Text = total.ToString();
            txtTotal22A26.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase24_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase24.Text != string.Empty)
        {
            int intTextBoxBase22 = Convert.ToInt32(TextBoxBase22.Text);
            int intTextBoxBase23 = Convert.ToInt32(TextBoxBase23.Text);
            int intTextBoxBase24 = Convert.ToInt32(TextBoxBase24.Text);
            int intTextBoxBase25 = Convert.ToInt32(TextBoxBase25.Text);
            int intTextBoxBase26 = Convert.ToInt32(TextBoxBase26.Text);


            int total = intTextBoxBase22 + intTextBoxBase23 + intTextBoxBase24 + intTextBoxBase25 + +intTextBoxBase26;

            txtTotal22A26.Text = total.ToString();
            txtTotal22A26.AutoUpdateAfterCallBack = true;
        }
    }
    protected void TextBoxBase25_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase25.Text != string.Empty)
        {
            int intTextBoxBase22 = Convert.ToInt32(TextBoxBase22.Text);
            int intTextBoxBase23 = Convert.ToInt32(TextBoxBase23.Text);
            int intTextBoxBase24 = Convert.ToInt32(TextBoxBase24.Text);
            int intTextBoxBase25 = Convert.ToInt32(TextBoxBase25.Text);
            int intTextBoxBase26 = Convert.ToInt32(TextBoxBase26.Text);


            int total = intTextBoxBase22 + intTextBoxBase23 + intTextBoxBase24 + intTextBoxBase25 + +intTextBoxBase26;

            txtTotal22A26.Text = total.ToString();
            txtTotal22A26.AutoUpdateAfterCallBack = true;
        }
    }

    protected void TextBoxBase26_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase26.Text != string.Empty)
        {
            int intTextBoxBase22 = Convert.ToInt32(TextBoxBase22.Text);
            int intTextBoxBase23 = Convert.ToInt32(TextBoxBase23.Text);
            int intTextBoxBase24 = Convert.ToInt32(TextBoxBase24.Text);
            int intTextBoxBase25 = Convert.ToInt32(TextBoxBase25.Text);
            int intTextBoxBase26 = Convert.ToInt32(TextBoxBase26.Text);


            int total = intTextBoxBase22 + intTextBoxBase23 + intTextBoxBase24 + intTextBoxBase25 + +intTextBoxBase26;

            txtTotal22A26.Text = total.ToString();
            txtTotal22A26.AutoUpdateAfterCallBack = true;
        }
    }


    protected void txtTotal22A26_TextChanged(object sender, EventArgs e)
    {
        if (TextBoxBase26.Text != string.Empty)
        {
            int intTextBoxBase22 = Convert.ToInt32(TextBoxBase22.Text);
            int intTextBoxBase23 = Convert.ToInt32(TextBoxBase23.Text);
            int intTextBoxBase24 = Convert.ToInt32(TextBoxBase24.Text);
            int intTextBoxBase25 = Convert.ToInt32(TextBoxBase25.Text);
            int intTextBoxBase26 = Convert.ToInt32(TextBoxBase26.Text);
            int total = intTextBoxBase22 + intTextBoxBase23 + intTextBoxBase24 + intTextBoxBase25 + +intTextBoxBase26;
            txtTotal22A26.Text = total.ToString();
            txtTotal22A26.AutoUpdateAfterCallBack = true;
        }
    }

    private void sumatoriaTotales()
    {


        int total;

        int intTextBoxBase5 = Convert.ToInt32(TextBoxBase5.Text);
        int intTextBoxBase6 = Convert.ToInt32(TextBoxBase6.Text);
        int intTextBoxBase7 = Convert.ToInt32(TextBoxBase7.Text);
        int intTextBoxBase8 = Convert.ToInt32(TextBoxBase8.Text);

         total = intTextBoxBase5 + intTextBoxBase6 + intTextBoxBase7 + intTextBoxBase8;

        txtTotal5A8.Text = total.ToString();
        txtTotal5A8.AutoUpdateAfterCallBack = true;

        int intTextBoxBase9 = Convert.ToInt32(TextBoxBase9.Text);
        int intTextBoxBase10 = Convert.ToInt32(TextBoxBase10.Text);


         total = intTextBoxBase9 + intTextBoxBase10;

        txtTotal9y10.Text = total.ToString();
        txtTotal9y10.AutoUpdateAfterCallBack = true;
        int intTextBoxBase11 = Convert.ToInt32(TextBoxBase11.Text);
        int intTextBoxBase12 = Convert.ToInt32(TextBoxBase12.Text);
        int intTextBoxBase13 = Convert.ToInt32(TextBoxBase13.Text);
        int intTextBoxBase14 = Convert.ToInt32(TextBoxBase14.Text);
        int intTextBoxBase15 = Convert.ToInt32(TextBoxBase15.Text);
        int intTextBoxBase16 = Convert.ToInt32(TextBoxBase16.Text);

         total = intTextBoxBase11 + intTextBoxBase12 + intTextBoxBase13 + intTextBoxBase14 + +intTextBoxBase15 + intTextBoxBase16;

        txtTotal11A16.Text = total.ToString();
        txtTotal11A16.AutoUpdateAfterCallBack = true;

        int intTextBoxBase17 = Convert.ToInt32(TextBoxBase17.Text);
        int intTextBoxBase18 = Convert.ToInt32(TextBoxBase18.Text);
        int intTextBoxBase19 = Convert.ToInt32(TextBoxBase19.Text);
        int intTextBoxBase20 = Convert.ToInt32(TextBoxBase20.Text);
        int intTextBoxBase21 = Convert.ToInt32(TextBoxBase21.Text);


         total = intTextBoxBase17 + intTextBoxBase18 + intTextBoxBase19 + intTextBoxBase20 + +intTextBoxBase21;

        txtTotal17A21.Text = total.ToString();
        txtTotal17A21.AutoUpdateAfterCallBack = true;

        int intTextBoxBase22 = Convert.ToInt32(TextBoxBase22.Text);
        int intTextBoxBase23 = Convert.ToInt32(TextBoxBase23.Text);
        int intTextBoxBase24 = Convert.ToInt32(TextBoxBase24.Text);
        int intTextBoxBase25 = Convert.ToInt32(TextBoxBase25.Text);
        int intTextBoxBase26 = Convert.ToInt32(TextBoxBase26.Text);
         total = intTextBoxBase22 + intTextBoxBase23 + intTextBoxBase24 + intTextBoxBase25 + +intTextBoxBase26;
        txtTotal22A26.Text = total.ToString();
        txtTotal22A26.AutoUpdateAfterCallBack = true;


    }
    protected void lblAccion_Click(object sender, EventArgs e)
    {
        crearContextItems();
        Server.Transfer("PlanAccionListado.aspx?SSM_ID=19", true);
    }
    protected void lblDescripcionRubro_Click(object sender, EventArgs e)
    {
        crearContextItems();
        Server.Transfer("EjecucionPresupuestal.aspx?SSM_ID=19", true);
    }
}
